module.exports = {
  template: Bue.html`<div>i am single jsx test file--{{foo}}
  
  <el-tree
  ref="tree"
  node-key="id"
  :props="props"
  :load="loadNode"
  lazy
  show-checkbox>
</el-tree>


<div class="buttons">
  <el-button @click="getCheckedNodes">通过 node 获取</el-button>
  <el-button @click="getCheckedKeys">通过 key 获取</el-button>
   <!-- <el-button @click="setCheckedNodes">通过 node 设置</el-button> -->
  <el-button @click="setCheckedKeys">通过 key 设置</el-button> 
  <el-button @click="resetChecked">清空</el-button>
</div>
  
  </div>`,
  methods: {
    getCheckedNodes() {
      console.log(this.$refs.tree.getCheckedNodes());
    },
    getCheckedKeys() {
      console.log(this.$refs.tree.getCheckedKeys());
    },
    // setCheckedNodes() {
    //   this.$refs.tree.setCheckedNodes([{
    //     id: 5,
    //     label: '二级 2-1'
    //   }, {
    //     id: 9,
    //     label: '三级 1-1-1'
    //   }]);
    // },
    setCheckedKeys() {
      this.$refs.tree.setCheckedKeys(['id0']);
    },
    resetChecked() {
      this.$refs.tree.setCheckedKeys([]);
    },
    loadNode(node, resolve) {
      // alert(node.level)
      if (node.level === 0) {
        return resolve([{ name: '帅帅好帅',id:'test' }]);
      }
      if (node.level > 0) {
        setTimeout(()=>{
          resolve([{
            name: '你是我的小丫小苹果'+node.level,
            id:'id'+node.level,
            leaf: true
          }, {
            name: '云哥威武'+node.level,
            id:'idd'+node.level,
          }]);
        },500)
      }

      // setTimeout(() => {
      //   const data = [{
      //     name: '你是我的小丫小苹果',
      //     leaf: true
      //   }, {
      //     name: '云哥威武'
      //   }];

      //   resolve(data);
      // }, 500);
    }
  },
  data() {
    return {
      props: {
        label: 'name',
        id:'id',
        children: '云哥威武s',
        isLeaf: 'leaf'
      },
      foo: "i am foo",
    };
  },
};
